home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 104 / MacAddict_104_2005-04.iso / Software / Internet & Communication / WordPress 1.2.2 freeware.dmg / wordpress / wp-admin / optionhandler.php < prev    next >
Encoding:
PHP Script  |  2004-01-03  |  4.9 KB  |  118 lines

  1. <?php
  2. require_once('../wp-config.php');
  3. /**
  4. ** get_option_widget()
  5. ** parameters:
  6. ** option_result - result set containing option_id, option_name, option_type,
  7. **                 option_value, option_description, option_admin_level
  8. ** editable      - flag to determine whether the returned widget will be editable
  9. **/
  10. function get_option_widget($option_result, $editable, $between)
  11. {
  12.     global $wpdb, $tableoptionvalues;
  13.     $disabled = $editable ? '' : 'disabled';
  14.  
  15.     switch ($option_result->option_type) {
  16.         case 1: // integer
  17.         case 3: // string
  18.         case 8: // float
  19.         case 6:  // range -- treat same as integer for now!
  20.             if (($option_result->option_type == 1) || ($option_result->option_type == 1)) {
  21.                 $width = 6;
  22.             } else {
  23.                 $width = $option_result->option_width;
  24.             }
  25.             return <<<TEXTINPUT
  26.                     <label for="$option_result->option_name">$option_result->option_name</label>$between
  27.                     <input type="text" name="$option_result->option_name" size="$width" value="$option_result->option_value" $disabled/>
  28. TEXTINPUT;
  29.             //break;
  30.  
  31.         case 2: // boolean
  32.             $true_selected = ($option_result->option_value == '1') ? 'selected' : '';
  33.             $false_selected = ($option_result->option_value == '0') ? 'selected' : '';
  34.             return <<<BOOLSELECT
  35.                     <label for="$option_result->option_name">$option_result->option_name</label>$between
  36.                     <select name="$option_result->option_name" $disabled>
  37.                     <option value="1" $true_selected>true</option>
  38.                     <option value="0" $false_selected>false</option>
  39.                     </select>
  40. BOOLSELECT;
  41.             //break;
  42.             
  43.         case 5: // select
  44.             $ret = <<<SELECT
  45.                     <label for="$option_result->option_name">$option_result->option_name</label>$between
  46.                     <select name="$option_result->option_name" id="$option_result->option_name" $disabled>
  47. SELECT;
  48.  
  49.             $select = $wpdb->get_results("SELECT optionvalue, optionvalue_desc "
  50.                                          ."FROM $tableoptionvalues "
  51.                                          ."WHERE option_id = $option_result->option_id "
  52.                                          ."ORDER BY optionvalue_seq");
  53.             if ($select) {
  54.                 foreach($select as $option) {
  55.                     $ret .= '<option value="'.$option->optionvalue.'"';
  56.                     //error_log("comparing [$option_result->option_value] == [$option->optionvalue]");
  57.                     if ($option_result->option_value == $option->optionvalue) {
  58.                         $ret .=' selected';
  59.                     }
  60.                     $ret .= ">$option->optionvalue_desc</option>\n";
  61.                 }
  62.             }
  63.             $ret .= '</select>';
  64.             return $ret;
  65.             //break;
  66.         
  67.         case 7: // SQL select
  68.             // first get the sql to run
  69.             $sql = $wpdb->get_var("SELECT optionvalue FROM $tableoptionvalues WHERE option_id = $option_result->option_id");
  70.             if (!$sql) {
  71.                 return $option_result->option_name . $editable;
  72.             }
  73.  
  74.             // now we may need to do table name substitution
  75.            eval("include('../wp-config.php');\$sql = \"$sql\";");
  76.  
  77.             $ret = <<<SELECT
  78.                     <label for="$option_result->option_name">$option_result->option_name</label>$between
  79.                     <select name="$option_result->option_name" $disabled>
  80. SELECT;
  81.     
  82.             $select = $wpdb->get_results("$sql");
  83.             if ($select) {
  84.                 foreach($select as $option) {
  85.                     $ret .= '<option value="'.$option->value.'"';
  86.                     //error_log("comparing [$option_result->option_value] == [$option->optionvalue]");
  87.                     if ($option_result->option_value == $option->value) {
  88.                         $ret .=' selected';
  89.                     }
  90.                     $ret .= ">$option->label</option>\n";
  91.                 }
  92.             }
  93.             $ret .= '</select>';
  94.             return $ret;
  95.             //break;
  96.  
  97.     } // end switch
  98.     return $option_result->option_name . $editable;
  99. } // end function get_option_widget
  100.  
  101.  
  102. function validate_option($option, $name, $val) {
  103.     global $wpdb, $tableoptionvalues;
  104.     $msg = '';
  105.     switch ($option->option_type) {
  106.         case 6: // range
  107.             // get range
  108.             $range = $wpdb->get_row("SELECT optionvalue_max, optionvalue_min FROM $tableoptionvalues WHERE option_id = $option->option_id");
  109.             if ($range) {
  110.                 if (($val < $range->optionvalue_min) || ($val > $range->optionvalue_max)) {
  111.                     $msg = "$name is outside the valid range ($range->optionvalue_min - $range->optionvalue_max). ";
  112.                 }
  113.             }
  114.     } // end switch
  115.     return $msg;
  116. } // end validate_option
  117.     
  118. ?>